package com.nononsenseapps.feeder.db

import android.content.Context
import androidx.room.Room
import com.nononsenseapps.feeder.db.room.AppDatabase
import org.junit.rules.ExternalResource

class TestDatabaseRule(val context: Context) : ExternalResource() {
    lateinit var db: AppDatabase

    override fun before() {
        db = Room.inMemoryDatabaseBuilder(
                context,
                AppDatabase::class.java
        ).build().also {
            // Ensure all classes use test database
            com.nononsenseapps.feeder.db.room.AppDatabase.setInstance(it)
        }
    }

    override fun after() {
        db.close()
    }
}
